import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

// 当push跳转时，多次跳转会在控制台报错，为了解决这个问题，我们可以重构push方法，利用catch捕获异常，从而不会在控制台产生错误
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function(url){
  return routerPush.call(this,url).catch(err => err)
}

const routes = [
  {
    path:"/",
    redirect:"/login"
  },
  {
    path:"/login",
    name:"login",
    meta:{
      title:"登录"
    },
    component:()=>import("../views/login/Login")
  },
  {
    path:"/layout",
    name:"layout",
    meta:{
      title:"首页"
    },
    component:() => import("../views/layout/Layout"),
    children:[
      {
        path:"welcome",
        name:"welcome",
        meta:{
          title:"首页"
        },
        component:()=>import("../views/welcome/Welcome.vue")
      },
      // {
      //   path:"adduser",
      //   name:"adduser",
      //   meta:{
      //     title:"添加用户"
      //   },
      //   component:()=>import("../views/users/AddUsers")
      // },
      // {
      //   path:"edituser",
      //   name:"edituser",
      //   meta:{
      //     title:"编辑用户"
      //   },
      //   component:()=>import("../views/users/AddUsers")
      // }
    ]
  }

]

const router = new VueRouter({
  routes,
  mode:"hash",
})
export default router
